//
//  HomeViewBtnCell.m
//  jingdongfang
//
//  Created by LJL on 2017/8/17.
//  Copyright © 2017年 BOE. All rights reserved.
//

#import "HomeViewBtnCell.h"
#import "HomeCellBtn.h"
#import "HomeViewArtGalleryVC.h"
#import "ArtDatabaseVC.h"
#import "RankListVC.h"
#import "IGHomeMenu.h"
#import "IGCommunityDetailVC.h"
#import "StoreCollectionVC.h"
#import "HomeActivityVC.h"
#import "HomeHDVC.h"
#import "IGHomeDailyVC.h"
@interface HomeViewBtnCell ()
{
    UIView *lineView;
}
@end

@implementation HomeViewBtnCell

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame])
    {
        [self loadUI];
        self.backgroundColor = [UIColor c3Color];
    }
    return self;
}


- (void)loadUI
{
    for (int i = 0; i < 8; i++)
    {
        HomeCellBtn *btn = [[HomeCellBtn alloc] init];
        btn.tag = 1000 + i;
        [btn addTarget:self action:@selector(cellBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        [self.contentView addSubview:btn];
        CGFloat wid = KSCREENWIDTH * 72 / 75 / 4;
        CGFloat hei = KSCREENWIDTH * 328 / 750 / 2 - 5;
        //九宫格的布局
        CGFloat  Direction_X = (wid*(i%4));
        CGFloat  Direction_Y  = (floorf(i/4.0)*hei);
        @KWeakObj(self);
        [btn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(selfWeak.contentView).offset(Direction_X);
            make.top.mas_equalTo(selfWeak.contentView).offset(Direction_Y);
            make.size.mas_equalTo(CGSizeMake(wid,wid));
        }];
    }
    

}

- (void)cellBtnClick:(HomeCellBtn *)btn
{
    switch (btn.tag) {
        case 1000:
            //每日推荐
            [UIViewController ig_pushViewController:[[IGHomeDailyVC alloc] init] animated:YES];
            break;
        case 1001:
            //画单
            [UIViewController ig_pushViewController:[[HomeHDVC alloc] init] animated:YES];
            break;
        case 1002:
            //排行榜
            [UIViewController ig_pushViewController:[[RankListVC alloc] initWithNibName:@"RankListVC" bundle:nil] animated:YES];
            break;
        case 1003:
            //艺术库
            [UIViewController ig_pushViewController:[[ArtDatabaseVC alloc] init] animated:YES];
            break;
        case 1004:
            //艺术馆
            [UIViewController ig_pushViewController:[[HomeViewArtGalleryVC alloc] init] animated:YES];
            break;
        case 1005:
            //商城
            [UIViewController ig_pushViewController:[[StoreCollectionVC alloc] init] animated:YES];            
            break;
        case 1006:
            //摄影
            [UIViewController ig_pushViewController:[[HomeActivityVC alloc] initWithType:PhotographyType] animated:YES];
            break;
        case 1007:
            //少儿艺术
            [UIViewController ig_pushViewController:[[HomeActivityVC alloc] initWithType:ChildType] animated:YES];
            break;

        default:
            break;
    }
}

- (void)setMenuArr:(NSMutableArray *)menuArr
{
    if (_menuArr == menuArr)
    {
        return;
    }
    _menuArr = menuArr;
    
    for (int i = 0; i < menuArr.count; i++)
    {
        IGHomeMenu *menu = menuArr[i];
        HomeCellBtn *btn = (HomeCellBtn *)[self.contentView viewWithTag:1000 + i];
        [btn.imageV sd_setImageWithURL:[NSURL URLWithString:menu.image] placeholderImage:[UIImage imageFromColor:[UIColor mainRandomColor]]];
        btn.label.text = menu.menu;
    }
}

@end
